package com.solotiger.douban.ui.base;

public abstract class BaseBarFragment extends BaseFragment {

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (mFront == hidden && isAdded()) {
            mFront = !hidden;
            if (mFront) {
                onShow();
            } else {
                onHide();
            }
        }
    }

    /********************
     * 生命周期重写, 使用onHide和onShow替代onPause和onResume
     ********************/
    @Deprecated
    @Override
    public void onPause() {
        super.onPause();
        if (isFront()) {
            onHide();
        }
    }

    @Deprecated
    @Override
    public void onResume() {
        super.onResume();
        if (isFront()) {
            onShow();
        }
    }

    /**
     * 当已经存在的Fragment被MainActivity切换为后台显示时调用
     */
    public void onHide() {
    }

    /**
     * 当已经存在的Fragment被MainActivity切换为前台显示时调用
     */
    public void onShow() {

    }

    protected boolean mFront = true;

    public boolean isFront() {
        return mFront;
    }
}
